package com.arethusa;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.table.TableColumn;

import simpleorm.core.SConnection;
import simpleorm.core.SPreparedStatement;
import simpleorm.core.SResultSet;
import simpleorm.core.SValidationException;
import simpleorm.ui.SUIConstants;

import com.arethusa.officialdb.Gefungeerdin;
import com.arethusa.officialdb.GefungeerdinBean;
import com.arethusa.officialdb.OfficialBean;
import com.ibm.j2x.swing.util.TableUtilities;
import com.ibm.j2x.util.CollectionUtilities;

public class OfficialDetails 
	extends JDialog 
	implements SUIConstants, WindowListener, MouseListener, ItemListener {

	private static final long serialVersionUID = 1L;

	private boolean kSR;
	private boolean kKA;
	private boolean kST;
	private boolean kJS;
	private boolean kT3;
	private boolean kT4;
	private boolean kMark;
	private boolean echtgenoot;
	private JDialog me;
	private boolean init = true;

	private JPanel jContentPane = null;
	private JPanel jDatailPanel = null;
	private JComboBox aanhefComboBox = null;
	private JTextField voorlettersTextField = null;
	private JTextField tussenvoegselTextField = null;
	private JTextField achternaamTextField = null;
	private JLabel adresLabel = null;
	private JTextField straatTextField = null;
	private JTextField postcodeTextField = null;
	private JTextField plaatsTextField = null;
	private JTextField landTextField = null;
	private JLabel landLabel = null;
	private JLabel telefoonLabel = null;
	private JTextField telefoonTextField = null;
	private JLabel opmerkingLabel = null;
	private JTextField opmerkingenTextField = null;
	private JLabel clubLabel = null;
	private JTextField clubTextField = null;
	private JLabel gefungeerdLabel = null;
	private JButton uitnodigenButton = null;
	private JLabel naamLabel = null;
	private JScrollPane jScrollPane = null;
	private JTable jTable = null;
	private List<?> olist;  //  @jve:decl-index=0:
	private JLabel kwalificatieLabel = null;
	private JPanel kwalificatiePanel = null;
	private JCheckBox SRCheckBox = null;
	private JCheckBox KACheckBox = null;
	private JCheckBox STCheckBox = null;
	private JCheckBox T3CheckBox = null;
	private JCheckBox JSCheckBox = null;
	private JCheckBox T4CheckBox = null;
	private JPanel buttonPanel = null;
	private JButton voerinButton = null;
	private JButton verwijderButton = null;
	private JButton okButton = null;
	private JButton wijzigButton = null;
	private JTextField idTextField = null;
	private JTextField echtgenootTextField = null;
	private JTextField eidTextField = null;
	private JCheckBox echtgenootCheckBox = null;

	private JCheckBox fungeertCheckBox = null;

	private class VoerinActionListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			if(idTextField.getText().equalsIgnoreCase("0")) {
				JOptionPane.showMessageDialog(null,
						"Sla eerst deze official op en selecteer hem opnieuw uit de lijst.",
						"Nieuwe official", JOptionPane.INFORMATION_MESSAGE);
			} else {
				NewFungering();
			}
		}

	}
	
	private class WijzigActionListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			ShowFungering();
		}

	}
	
	private class VerwijderActionListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			DeleteFungering();
		}

	}
	
	private class OkActionListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			UpdateOfficial();
			me.setVisible(false);
		}
		
	}

	public void UpdateOfficial() {
		try {
			OfficialBean f = new OfficialBean();
			f.setOfficialid(new Long(idTextField.getText()));
			f.setAanhef((String)aanhefComboBox.getSelectedItem());
			f.setVoorletters(voorlettersTextField.getText());
			f.setTussenvoegsel(tussenvoegselTextField.getText());
			f.setAchternaam(achternaamTextField.getText());
			f.setAdres(straatTextField.getText());
			f.setPostcode(postcodeTextField.getText());
			f.setPlaats(plaatsTextField.getText());
			f.setLand(landTextField.getText());
			f.setTelefoon(telefoonTextField.getText());
			f.setOpmerkingen(opmerkingenTextField.getText());
			if( echtgenoot ) {
				f.setEchtgenootid(new Long(eidTextField.getText()));
				f.setEchtpaar(new Boolean(true));
			} else {
				f.setEchtgenootid(new Long(0));
				f.setEchtpaar(new Boolean(false));
			}
			f.setClub(clubTextField.getText());
			f.setSr(new Boolean(kSR));
			f.setKa(new Boolean(kKA));
			f.setSt(new Boolean(kST));
			f.setJs(new Boolean(kJS));
			f.setT3(new Boolean(kT3));
			f.setT4(new Boolean(kT4));
			f.setMark(new Boolean(kMark));
			if(f.getOfficialid().compareTo(0L) == 0) {
				f.create();
			} else {
				f.update();
			}
		} catch (SValidationException e1) {
			JOptionPane.showMessageDialog(null,
				e1.getMessage(),
				"Validatie", JOptionPane.ERROR_MESSAGE);
		} catch (NumberFormatException e2) {
			JOptionPane.showMessageDialog(null,
				"Jaar moet een nummer zijn.",
				"Validatie", JOptionPane.ERROR_MESSAGE);
		}

	}
	
	public void NewFungering() {
		GefungeerdinBean f = new GefungeerdinBean();
		f.setOfficialid(new Long(idTextField.getText()));
		f.setJaar(new Long(0));
		f.setGevraagd(true);
		f.setGefungeerd(false);
		f.setFunktie("");
		f.setReden("");
		Fungeren dlg = new Fungeren(null);
		dlg.getJaarComboBox().setEnabled(true);
		dlg.setLocationRelativeTo(null);
		dlg.setFungering(f);
		dlg.setVisible(true);
		fillTable(f.getOfficialid());
	}
	
	public void ShowFungering() {
		int row = getJTable().getSelectedRow();
		if(row == -1) {
			JOptionPane.showMessageDialog(null,
					"Selecteer eerst een jaar uit de tabel.",
					"Selectie fout", JOptionPane.INFORMATION_MESSAGE);
			
		} else {
			GefungeerdinBean f = ((GefungeerdinBean)olist.get(row));
			f.read();
			Fungeren dlg = new Fungeren(null);
			dlg.getJaarComboBox().setEnabled(false);
			dlg.setLocationRelativeTo(null);
			dlg.setFungering(f);
			dlg.setVisible(true);
			fillTable(f.getOfficialid());
		}
	}
	
	public void DeleteFungering() {
		int row = getJTable().getSelectedRow();
		if(row == -1) {
			JOptionPane.showMessageDialog(null,
					"Selecteer eerst een jaar uit de tabel.",
					"Selectie fout", JOptionPane.INFORMATION_MESSAGE);
			
		} else {
			GefungeerdinBean f = ((GefungeerdinBean)olist.get(row));
			f.delete();
			fillTable(f.getOfficialid());
		}
	}
	
	private OfficialBean selectEchtgenoot() {
		SelectOfficial dlg = new SelectOfficial(null);
		dlg.setLocationRelativeTo(null);
		dlg.setVisible(true);
		OfficialBean eo = null;
		eo = dlg.getOfficial();
		return eo;
	}
	/**
	 * @param owner
	 */
	public OfficialDetails(Frame owner) {
		super(owner);
		me=this;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(534, 484);
		this.setTitle("Official gegevens");
		this.setModal(true);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.setContentPane(getJContentPane());
	}
	
	public void setOfficial(OfficialBean o) {
		init = true;
		idTextField.setText(o.getOfficialid().toString());
		aanhefComboBox.setSelectedItem(o.getAanhef());
		voorlettersTextField.setText(o.getVoorletters());
		tussenvoegselTextField.setText(o.getTussenvoegsel());
		achternaamTextField.setText(o.getAchternaam());
		straatTextField.setText(o.getAdres());
		postcodeTextField.setText(o.getPostcode());
		plaatsTextField.setText(o.getPlaats());
		landTextField.setText(o.getLand());
		telefoonTextField.setText(o.getTelefoon());
		opmerkingenTextField.setText(o.getOpmerkingen());
		if(o.getEchtpaar().booleanValue()) {
			OfficialBean oe = new OfficialBean();
			oe.setOfficialid(o.getEchtgenootid());
			oe.read();
        	echtgenootTextField.setText(
        			oe.getAanhef()+" "+oe.getVoorletters()+" "+
        			oe.getTussenvoegsel()+" "+oe.getAchternaam()+
        			", "+oe.getPlaats());
			echtgenootCheckBox.setSelected(true);
			echtgenoot = true;
			eidTextField.setText(o.getEchtgenootid().toString());
		} else {
			echtgenootTextField.setText("");
			echtgenootCheckBox.setSelected(false);
			echtgenoot = false;
			eidTextField.setText("0");
		}
		clubTextField.setText(o.getClub());
		SRCheckBox.setSelected(o.getSr().booleanValue());
		KACheckBox.setSelected(o.getKa().booleanValue());
		STCheckBox.setSelected(o.getSt().booleanValue());
		T3CheckBox.setSelected(o.getT3().booleanValue());
		T4CheckBox.setSelected(o.getT4().booleanValue());
		JSCheckBox.setSelected(o.getJs().booleanValue());
		fungeertCheckBox.setSelected(o.getMark().booleanValue());
		fillTable(o.getOfficialid());
		init= false;
	}

	private void fillTable(Long ofid) {
		List<GefungeerdinBean> tmp = new ArrayList<GefungeerdinBean>();
		/// Prepare and execute the query
		boolean hasBegun = SConnection.getConnection().hasBegun();
		if( ! hasBegun ) { SConnection.begin(); }
		SPreparedStatement stmt = Gefungeerdin.meta.select(
				"OfficialID="+ofid, "JAAR");
		SResultSet res = stmt.execute();
		
		/// loop through the results
		while (res.hasNext()) {
			GefungeerdinBean strt = new GefungeerdinBean(((Gefungeerdin)res.getRecord()));
			tmp.add(strt);
		}
		if( ! hasBegun ) { SConnection.commit(); }
    	olist = CollectionUtilities.observableList(tmp);
		TableUtilities.setViewToModel("OfficialModel.xml", "Gefungeerdin", getJTable(), olist);
		TableColumn col1 = getJTable().getColumnModel().getColumn(0);
		col1.setMaxWidth(50);
		TableColumn col2 = getJTable().getColumnModel().getColumn(1);
		col2.setMaxWidth(100);
		TableColumn col3 = getJTable().getColumnModel().getColumn(2);
		col3.setMaxWidth(100);
		TableColumn col4 = getJTable().getColumnModel().getColumn(3);
		col4.setMaxWidth(50);
		TableColumn col5 = getJTable().getColumnModel().getColumn(4);
		col5.setPreferredWidth(100);
		}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJDatailPanel(), BorderLayout.NORTH);
			jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jDatailPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJDatailPanel() {
		if (jDatailPanel == null) {
			GridBagConstraints gridBagConstraints112 = new GridBagConstraints();
			gridBagConstraints112.gridx = 0;
			gridBagConstraints112.gridwidth = 2;
			gridBagConstraints112.gridy = 7;
			GridBagConstraints gridBagConstraints111 = new GridBagConstraints();
			gridBagConstraints111.gridx = 0;
			gridBagConstraints111.gridwidth = 2;
			gridBagConstraints111.gridy = 4;
			GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
			gridBagConstraints41.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints41.gridy = 4;
			gridBagConstraints41.weightx = 1.0;
			gridBagConstraints41.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints41.ipadx = 50;
			gridBagConstraints41.gridx = 6;
			GridBagConstraints gridBagConstraints33 = new GridBagConstraints();
			gridBagConstraints33.fill = GridBagConstraints.BOTH;
			gridBagConstraints33.gridy = 4;
			gridBagConstraints33.weightx = 1.0;
			gridBagConstraints33.gridwidth = 4;
			gridBagConstraints33.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints33.anchor = GridBagConstraints.WEST;
			gridBagConstraints33.gridx = 2;
			GridBagConstraints gridBagConstraints110 = new GridBagConstraints();
			gridBagConstraints110.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints110.gridy = 1;
			gridBagConstraints110.weightx = 1.0;
			gridBagConstraints110.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints110.ipadx = 50;
			gridBagConstraints110.gridx = 6;
			GridBagConstraints gridBagConstraints32 = new GridBagConstraints();
			gridBagConstraints32.gridx = 6;
			gridBagConstraints32.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints32.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints32.gridy = 0;
			GridBagConstraints gridBagConstraints26 = new GridBagConstraints();
			gridBagConstraints26.gridx = 2;
			gridBagConstraints26.gridwidth = 5;
			gridBagConstraints26.anchor = GridBagConstraints.EAST;
			gridBagConstraints26.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints26.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints26.gridy = 8;
			GridBagConstraints gridBagConstraints22 = new GridBagConstraints();
			gridBagConstraints22.gridx = 2;
			gridBagConstraints22.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints22.gridwidth = 4;
			gridBagConstraints22.anchor = GridBagConstraints.WEST;
			gridBagConstraints22.gridy = 6;
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.gridx = 0;
			gridBagConstraints1.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints1.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints1.anchor = GridBagConstraints.EAST;
			gridBagConstraints1.gridwidth = 2;
			gridBagConstraints1.gridy = 6;
			kwalificatieLabel = new JLabel();
			kwalificatieLabel.setText("Kwalificatie");
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			naamLabel = new JLabel();
			naamLabel.setText("Naam");
			GridBagConstraints gridBagConstraints61 = new GridBagConstraints();
			gridBagConstraints61.anchor = GridBagConstraints.SOUTHWEST;
			gridBagConstraints61.gridwidth = 2;
			gridBagConstraints61.gridx = 0;
			gridBagConstraints61.gridy = 8;
			gridBagConstraints61.insets = new Insets(5, 5, 5, 5);
			gefungeerdLabel = new JLabel();
			gefungeerdLabel.setText("heeft gefungeerd in");
			GridBagConstraints gridBagConstraints24 = new GridBagConstraints();
			gridBagConstraints24.anchor = GridBagConstraints.WEST;
			gridBagConstraints24.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints24.gridwidth = 3;
			gridBagConstraints24.gridx = 1;
			gridBagConstraints24.gridy = 5;
			gridBagConstraints24.ipadx = 150;
			gridBagConstraints24.weightx = 1.0;
			gridBagConstraints24.fill = GridBagConstraints.VERTICAL;
			GridBagConstraints gridBagConstraints23 = new GridBagConstraints();
			gridBagConstraints23.anchor = GridBagConstraints.EAST;
			gridBagConstraints23.gridx = 0;
			gridBagConstraints23.gridy = 5;
			gridBagConstraints23.insets = new Insets(5, 5, 5, 5);
			clubLabel = new JLabel();
			clubLabel.setText("Club");
			GridBagConstraints gridBagConstraints19 = new GridBagConstraints();
			gridBagConstraints19.anchor = GridBagConstraints.WEST;
			gridBagConstraints19.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints19.gridwidth = 5;
			gridBagConstraints19.gridx = 1;
			gridBagConstraints19.gridy = 3;
			gridBagConstraints19.fill = GridBagConstraints.BOTH;
			GridBagConstraints gridBagConstraints18 = new GridBagConstraints();
			gridBagConstraints18.anchor = GridBagConstraints.EAST;
			gridBagConstraints18.gridx = 0;
			gridBagConstraints18.gridy = 3;
			gridBagConstraints18.insets = new Insets(5, 5, 5, 5);
			opmerkingLabel = new JLabel();
			opmerkingLabel.setText("Opm.");
			GridBagConstraints gridBagConstraints17 = new GridBagConstraints();
			gridBagConstraints17.anchor = GridBagConstraints.WEST;
			gridBagConstraints17.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints17.gridwidth = 2;
			gridBagConstraints17.gridx = 4;
			gridBagConstraints17.gridy = 2;
			gridBagConstraints17.ipadx = 100;
			gridBagConstraints17.fill = GridBagConstraints.VERTICAL;
			GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
			gridBagConstraints16.anchor = GridBagConstraints.EAST;
			gridBagConstraints16.gridx = 3;
			gridBagConstraints16.gridy = 2;
			gridBagConstraints16.insets = new Insets(5, 5, 5, 5);
			telefoonLabel = new JLabel();
			telefoonLabel.setText("Telno");
			GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
			gridBagConstraints15.anchor = GridBagConstraints.EAST;
			gridBagConstraints15.gridx = 0;
			gridBagConstraints15.gridy = 2;
			gridBagConstraints15.insets = new Insets(5, 5, 5, 5);
			landLabel = new JLabel();
			landLabel.setText("Land");
			GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
			gridBagConstraints14.anchor = GridBagConstraints.WEST;
			gridBagConstraints14.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints14.gridwidth = 2;
			gridBagConstraints14.gridx = 1;
			gridBagConstraints14.gridy = 2;
			gridBagConstraints14.ipadx = 100;
			gridBagConstraints14.fill = GridBagConstraints.BOTH;
			GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
			gridBagConstraints13.fill = GridBagConstraints.BOTH;
			gridBagConstraints13.gridx = 5;
			gridBagConstraints13.gridy = 1;
			gridBagConstraints13.ipadx = 120;
			gridBagConstraints13.insets = new Insets(5, 5, 5, 5);
			GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
			gridBagConstraints12.fill = GridBagConstraints.BOTH;
			gridBagConstraints12.gridx = 4;
			gridBagConstraints12.gridy = 1;
			gridBagConstraints12.ipadx = 50;
			gridBagConstraints12.insets = new Insets(5, 5, 5, 5);
			GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
			gridBagConstraints11.anchor = GridBagConstraints.WEST;
			gridBagConstraints11.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints11.gridwidth = 3;
			gridBagConstraints11.gridx = 1;
			gridBagConstraints11.gridy = 1;
			gridBagConstraints11.ipadx = 170;
			gridBagConstraints11.fill = GridBagConstraints.VERTICAL;
			GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
			gridBagConstraints10.anchor = GridBagConstraints.EAST;
			gridBagConstraints10.gridx = 0;
			gridBagConstraints10.gridy = 1;
			gridBagConstraints10.insets = new Insets(5, 5, 5, 5);
			adresLabel = new JLabel();
			adresLabel.setText("Adres");
			GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
			gridBagConstraints9.fill = GridBagConstraints.BOTH;
			gridBagConstraints9.gridwidth = 2;
			gridBagConstraints9.gridx = 4;
			gridBagConstraints9.gridy = 0;
			gridBagConstraints9.weightx = 1.0;
			gridBagConstraints9.insets = new Insets(5, 5, 5, 5);
			GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
			gridBagConstraints8.anchor = GridBagConstraints.WEST;
			gridBagConstraints8.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints8.gridx = 3;
			gridBagConstraints8.gridy = 0;
			gridBagConstraints8.ipadx = 50;
			gridBagConstraints8.fill = GridBagConstraints.VERTICAL;
			GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
			gridBagConstraints7.anchor = GridBagConstraints.CENTER;
			gridBagConstraints7.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints7.gridx = 2;
			gridBagConstraints7.gridy = 0;
			gridBagConstraints7.ipadx = 40;
			gridBagConstraints7.fill = GridBagConstraints.BOTH;
			GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
			gridBagConstraints5.anchor = GridBagConstraints.WEST;
			gridBagConstraints5.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints5.gridx = 1;
			gridBagConstraints5.gridy = 0;
			gridBagConstraints5.ipadx = 25;
			gridBagConstraints5.weightx = 0.0D;
			gridBagConstraints5.fill = GridBagConstraints.VERTICAL;
			jDatailPanel = new JPanel();
			jDatailPanel.setLayout(new GridBagLayout());
			jDatailPanel.add(getAanhefComboBox(), gridBagConstraints5);
			jDatailPanel.add(getVoorlettersTextField(), gridBagConstraints7);
			jDatailPanel.add(getTussenvoegselTextField(), gridBagConstraints8);
			jDatailPanel.add(getAchternaamTextField(), gridBagConstraints9);
			jDatailPanel.add(adresLabel, gridBagConstraints10);
			jDatailPanel.add(getStraatTextField(), gridBagConstraints11);
			jDatailPanel.add(getPostcodeTextField(), gridBagConstraints12);
			jDatailPanel.add(getPlaatsTextField(), gridBagConstraints13);
			jDatailPanel.add(getLandTextField(), gridBagConstraints14);
			jDatailPanel.add(landLabel, gridBagConstraints15);
			jDatailPanel.add(telefoonLabel, gridBagConstraints16);
			jDatailPanel.add(getTelefoonTextField(), gridBagConstraints17);
			jDatailPanel.add(opmerkingLabel, gridBagConstraints18);
			jDatailPanel.add(getOpmerkingenTextField(), gridBagConstraints19);
			jDatailPanel.add(clubLabel, gridBagConstraints23);
			jDatailPanel.add(getClubTextField(), gridBagConstraints24);
			jDatailPanel.add(gefungeerdLabel, gridBagConstraints61);
			jDatailPanel.add(naamLabel, gridBagConstraints);
			jDatailPanel.add(getButtonPanel(), gridBagConstraints26);
			jDatailPanel.add(kwalificatieLabel, gridBagConstraints1);
			jDatailPanel.add(getKwalificatiePanel(), gridBagConstraints22);
			jDatailPanel.add(getOkButton(), gridBagConstraints32);
			jDatailPanel.add(getIdTextField(), gridBagConstraints110);
			jDatailPanel.add(getEchtgenootTextField(), gridBagConstraints33);
			jDatailPanel.add(getEidTextField(), gridBagConstraints41);
			jDatailPanel.add(getEchtgenootCheckBox(), gridBagConstraints111);
			jDatailPanel.add(getFungeertCheckBox(), gridBagConstraints112);
		}
		return jDatailPanel;
	}

	/**
	 * This method initializes aanhefComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getAanhefComboBox() {
		if (aanhefComboBox == null) {
			aanhefComboBox = new JComboBox();
			aanhefComboBox.setPreferredSize(new Dimension(31, 20));
			aanhefComboBox.addItem(new String("Heer"));
			aanhefComboBox.addItem(new String("Mevr"));
		}
		return aanhefComboBox;
	}

	/**
	 * This method initializes voorlettersTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getVoorlettersTextField() {
		if (voorlettersTextField == null) {
			voorlettersTextField = new JTextField();
		}
		return voorlettersTextField;
	}

	/**
	 * This method initializes tussenvoegselTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTussenvoegselTextField() {
		if (tussenvoegselTextField == null) {
			tussenvoegselTextField = new JTextField();
		}
		return tussenvoegselTextField;
	}

	/**
	 * This method initializes achternaamTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getAchternaamTextField() {
		if (achternaamTextField == null) {
			achternaamTextField = new JTextField();
		}
		return achternaamTextField;
	}

	/**
	 * This method initializes straatTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getStraatTextField() {
		if (straatTextField == null) {
			straatTextField = new JTextField();
		}
		return straatTextField;
	}

	/**
	 * This method initializes postcodeTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getPostcodeTextField() {
		if (postcodeTextField == null) {
			postcodeTextField = new JTextField();
		}
		return postcodeTextField;
	}

	/**
	 * This method initializes plaatsTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getPlaatsTextField() {
		if (plaatsTextField == null) {
			plaatsTextField = new JTextField();
		}
		return plaatsTextField;
	}

	/**
	 * This method initializes landTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getLandTextField() {
		if (landTextField == null) {
			landTextField = new JTextField();
			landTextField.setText("");
		}
		return landTextField;
	}

	/**
	 * This method initializes telefoonTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTelefoonTextField() {
		if (telefoonTextField == null) {
			telefoonTextField = new JTextField();
		}
		return telefoonTextField;
	}

	/**
	 * This method initializes opmerkingenTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getOpmerkingenTextField() {
		if (opmerkingenTextField == null) {
			opmerkingenTextField = new JTextField();
		}
		return opmerkingenTextField;
	}

	/**
	 * This method initializes clubTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getClubTextField() {
		if (clubTextField == null) {
			clubTextField = new JTextField();
		}
		return clubTextField;
	}

	/**
	 * This method initializes uitnodigenButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getUitnodigenButton() {
		if (uitnodigenButton == null) {
			uitnodigenButton = new JButton();
			uitnodigenButton.setText("Nodig uit");
			uitnodigenButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
				}
			});
		}
		return uitnodigenButton;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTable	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTable() {
		if (jTable == null) {
			jTable = new JTable();
	        jTable.addMouseListener(this);
		}
		return jTable;
	}
	
	/**
	 * This method initializes kwalificatiePanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getKwalificatiePanel() {
		if (kwalificatiePanel == null) {
			GridBagConstraints gridBagConstraints28 = new GridBagConstraints();
			gridBagConstraints28.insets = new Insets(0, 0, 0, 10);
			GridBagConstraints gridBagConstraints27 = new GridBagConstraints();
			gridBagConstraints27.insets = new Insets(0, 0, 0, 10);
			GridBagConstraints gridBagConstraints25 = new GridBagConstraints();
			gridBagConstraints25.insets = new Insets(0, 0, 0, 10);
			GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
			gridBagConstraints6.insets = new Insets(0, 0, 0, 10);
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.insets = new Insets(0, 0, 0, 10);
			kwalificatiePanel = new JPanel();
			kwalificatiePanel.setLayout(new GridBagLayout());
			kwalificatiePanel.add(getSRCheckBox(), gridBagConstraints3);
			kwalificatiePanel.add(getKACheckBox(), gridBagConstraints6);
			kwalificatiePanel.add(getSTCheckBox(), gridBagConstraints25);
			kwalificatiePanel.add(getJSCheckBox(), gridBagConstraints27);
			kwalificatiePanel.add(getT3CheckBox(), gridBagConstraints28);
			kwalificatiePanel.add(getT4CheckBox(), new GridBagConstraints());
		}
		return kwalificatiePanel;
	}

	/**
	 * This method initializes SRCheckBox	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getSRCheckBox() {
		if (SRCheckBox == null) {
			SRCheckBox = new JCheckBox();
			SRCheckBox.setText("1");
			SRCheckBox.addItemListener(this);
		}
		return SRCheckBox;
	}

	/**
	 * This method initializes KACheckBox	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getKACheckBox() {
		if (KACheckBox == null) {
			KACheckBox = new JCheckBox();
			KACheckBox.setText("K");
			KACheckBox.addItemListener(this);
		}
		return KACheckBox;
	}

	/**
	 * This method initializes STCheckBox	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getSTCheckBox() {
		if (STCheckBox == null) {
			STCheckBox = new JCheckBox();
			STCheckBox.setText("2");
			STCheckBox.addItemListener(this);
		}
		return STCheckBox;
	}

	/**
	 * This method initializes T3CheckBox	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getT3CheckBox() {
		if (T3CheckBox == null) {
			T3CheckBox = new JCheckBox();
			T3CheckBox.setText("3");
			T3CheckBox.addItemListener(this);
		}
		return T3CheckBox;
	}

	/**
	 * This method initializes JSCheckBox	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJSCheckBox() {
		if (JSCheckBox == null) {
			JSCheckBox = new JCheckBox();
			JSCheckBox.setText("J");
			JSCheckBox.addItemListener(this);
		}
		return JSCheckBox;
	}

	/**
	 * This method initializes T4CheckBox	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getT4CheckBox() {
		if (T4CheckBox == null) {
			T4CheckBox = new JCheckBox();
			T4CheckBox.setText("4");
			T4CheckBox.addItemListener(this);
		}
		return T4CheckBox;
	}

	public void windowActivated(WindowEvent e) {}
	public void windowClosed(WindowEvent e) {
		
	}
	public void windowClosing(WindowEvent e) {}
	public void windowDeactivated(WindowEvent e) {}
	public void windowDeiconified(WindowEvent e) {}
	public void windowIconified(WindowEvent e) {}
	public void windowOpened(WindowEvent e) {}

	/**
	 * This method initializes buttonPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getButtonPanel() {
		if (buttonPanel == null) {
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.gridx = 1;
			gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints2.gridy = 0;
			GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
			gridBagConstraints31.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints31.gridy = 0;
			gridBagConstraints31.gridx = 4;
			GridBagConstraints gridBagConstraints30 = new GridBagConstraints();
			gridBagConstraints30.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints30.gridx = 2;
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
			gridBagConstraints4.insets = new Insets(5, 5, 5, 5);
			buttonPanel = new JPanel();
			buttonPanel.setLayout(new GridBagLayout());
			buttonPanel.add(getVoerinButton(), gridBagConstraints4);
			buttonPanel.add(getVerwijderButton(), gridBagConstraints30);
			buttonPanel.add(getUitnodigenButton(), gridBagConstraints31);
			buttonPanel.add(getWijzigButton(), gridBagConstraints2);
		}
		return buttonPanel;
	}

	/**
	 * This method initializes voerinButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getVoerinButton() {
		if (voerinButton == null) {
			voerinButton = new JButton();
			voerinButton.setText("Voer in");
			voerinButton.addActionListener(new VoerinActionListener());
		}
		return voerinButton;
	}

	/**
	 * This method initializes verwijderButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getVerwijderButton() {
		if (verwijderButton == null) {
			verwijderButton = new JButton();
			verwijderButton.setText("Verwijder");
			verwijderButton.addActionListener(new VerwijderActionListener());
		}
		return verwijderButton;
	}

	/**
	 * This method initializes okButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getOkButton() {
		if (okButton == null) {
			okButton = new JButton();
			okButton.setText("Wijzig");
			okButton.addActionListener(new OkActionListener());
		}
		return okButton;
	}

	/**
	 * This method initializes wijzigButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getWijzigButton() {
		if (wijzigButton == null) {
			wijzigButton = new JButton();
			wijzigButton.setText("Wijzig");
			wijzigButton.addActionListener(new WijzigActionListener());
		}
		return wijzigButton;
	}

	public void mouseClicked(MouseEvent e) {
		if(e.getSource().equals(jTable) ){
			int n = e.getClickCount();
			if(n==1) return;
			ShowFungering();
		}
	}

	public void mouseEntered(MouseEvent e) {}
	public void mouseExited(MouseEvent e) {}
	public void mousePressed(MouseEvent e) {}
	public void mouseReleased(MouseEvent e) {}

	public void itemStateChanged(ItemEvent e) {
        Object source = e.getItemSelectable();

        if (source == getSRCheckBox()) {
            kSR = (e.getStateChange() == ItemEvent.SELECTED);
        } else if (source == getKACheckBox()) {
            kKA = (e.getStateChange() == ItemEvent.SELECTED);
        } else if (source == getSTCheckBox()) {
            kST = (e.getStateChange() == ItemEvent.SELECTED);
        } else if (source == getJSCheckBox()) {
            kJS = (e.getStateChange() == ItemEvent.SELECTED);
        } else if (source == getT3CheckBox()) {
            kT3 = (e.getStateChange() == ItemEvent.SELECTED);
        } else if (source == getT4CheckBox()) {
            kT4 = (e.getStateChange() == ItemEvent.SELECTED);
        } else if (source == getFungeertCheckBox()) {
            kMark = (e.getStateChange() == ItemEvent.SELECTED);
        } else if (source == getEchtgenootCheckBox()&& !init) {
            echtgenoot = (e.getStateChange() == ItemEvent.SELECTED);
            if( echtgenoot ){
            	OfficialBean eo = selectEchtgenoot();
            	if( eo.equals(null) ) {
    				echtgenootTextField.setText("");
    				echtgenootCheckBox.setSelected(false);
    				eidTextField.setText("0");
            	} else {
                	echtgenootTextField.setText(
                			eo.getAanhef()+" "+eo.getVoorletters()+" "+
                			eo.getTussenvoegsel()+" "+eo.getAchternaam()+
                			", "+eo.getPlaats());
	            	eidTextField.setText(eo.getOfficialid().toString());
            	}
            } else {
				echtgenootTextField.setText("");
				echtgenootCheckBox.setSelected(false);
				eidTextField.setText("0");
            }
        }
	}

	/**
	 * This method initializes idTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getIdTextField() {
		if (idTextField == null) {
			idTextField = new JTextField();
			idTextField.setVisible(false);
		}
		return idTextField;
	}

	/**
	 * This method initializes echtgenootTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getEchtgenootTextField() {
		if (echtgenootTextField == null) {
			echtgenootTextField = new JTextField();
		}
		return echtgenootTextField;
	}

	/**
	 * This method initializes eidTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getEidTextField() {
		if (eidTextField == null) {
			eidTextField = new JTextField();
			eidTextField.setVisible(false);
		}
		return eidTextField;
	}

	/**
	 * This method initializes echtgenootCheckBox	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getEchtgenootCheckBox() {
		if (echtgenootCheckBox == null) {
			echtgenootCheckBox = new JCheckBox();
			echtgenootCheckBox.setText("is echtgenoot van");
			echtgenootCheckBox.addItemListener(this);
		}
		return echtgenootCheckBox;
	}

	/**
	 * This method initializes fungeertCheckBox	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getFungeertCheckBox() {
		if (fungeertCheckBox == null) {
			fungeertCheckBox = new JCheckBox();
			fungeertCheckBox.setText("fungeert niet meer");
			fungeertCheckBox.addItemListener(this);
		}
		return fungeertCheckBox;
	}

}
